<!DOCTYPE html>
<html>
<head>
    <title>门诊查询--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <link rel="stylesheet" type="text/css" href="../Css/disableHyperlink.css">
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/webUtil.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }


    </style>
    <script type="text/javascript">
	 $(function () {
		$('#newNav').click(function(){
				window.location.href="add.html";
		 });
    });
	
    	function checkall(){
			var alls=document.getElementsByName("check");
			var ch=document.getElementById("checkall");
			if(ch.checked){
				for(var i=0;i<alls.length;i++){
					alls[i].checked=true;	
				}	
			}else{
				for(var i=0;i<alls.length;i++){
					alls[i].checked=false;	
				}	
			}
		}
		function delAll(){
			var alls=document.getElementsByName("check");
			var ids=new Array();
			for(var i=0;i<alls.length;i++){
				if(alls[i].checked){
					ids.push(alls[i].value);
				}		
			}
			if(ids.length>0){
				if(confirm("确认操作?")){
					alert("成功!");
				}
			}else{
				alert("请选中要操作的项");
			}
		}
    </script>
</head>
<body>

<form id="queryForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <input name="index" type="hidden"/>
    <input name="size" value="5" type="hidden"/>
    <tr>
        <td width="10%" class="tableleft">病历号：</td>
        <td><input type="text" name="registerId" id="registerId" value=""/></td>
		
        <td width="10%" class="tableleft">主治医生：</td>
        <td><input type="text" name="doctorName" id="doctorName" value=""/></td>
		
        <td width="10%" class="tableleft">科室：</td>
        <td><input type="text" name="departmentName" id="departmentName" value=""/></td>
    </tr>
    <tr>
		
        <td width="10%" class="tableleft">挂号时间：</td>
		  <td colspan="5">
			<input type="date" name="preDate" id="preDate" value=""/>&nbsp;至&nbsp;<input type="date" id="lastDate" name="lastDate" value=""/>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <button id="query" class="btn btn-primary" type="button">查询</button>
            <button id="clear" class="btn btn-primary" type="button">清空</button>
			
        </td>
    </tr>
</table>
</form>
   
<table class="table table-bordered table-hover definewidth m10" >
   <thead>
    <tr>
    	<th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>门诊编号</th>
        <th>主治医生</th>
        <th>挂号时间</th>
        <th>挂号科室</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tbody">
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1103</td>
            <td style="vertical-align:middle;">程俊</td>
            <td style="vertical-align:middle;">2015-09-09 12：12：12</td>
            <td style="vertical-align:middle;">血液科</td>
            <td style="vertical-align:middle;">已挂号</td>
            <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;
                <a href="edit.html">更改</a>&nbsp;&nbsp;&nbsp;
                <a href="javascript:alert('退号成功！');">退号</a></td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1104</td>
            <td style="vertical-align:middle;">王博</td>
            <td style="vertical-align:middle;">2015-12-09 12：12：12</td>
            <td style="vertical-align:middle;">骨科</td>
            <td style="vertical-align:middle;">已住院</td>
            <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a></td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1105</td>
            <td style="vertical-align:middle;">沈青川</td>
            <td style="vertical-align:middle;">2015-02-04 15：11：12</td>
            <td style="vertical-align:middle;">外科</td>
            <td style="vertical-align:middle;">已住院</td>
            <td style="vertical-align:middle;"><a href="look.html">详情>>></a>&nbsp;&nbsp;&nbsp;<a href="edit.html">更改</a></td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1106</td>
            <td style="vertical-align:middle;">欧阳雨露</td>
            <td style="vertical-align:middle;">2014-09-05 12：12：12</td>
            <td style="vertical-align:middle;">急诊科</td>
            <td style="vertical-align:middle;">已出院</td>
             <td style="vertical-align:middle;"><a href="look.html">详情>>></a></td>
        </tr>
	     <tr >
         	<td style="vertical-align:middle;"><input type="checkbox" name="check" value="1"></td>
            <td style="vertical-align:middle;">1107</td>
            <td style="vertical-align:middle;">艾小天</td>
            <td style="vertical-align:middle;">2014-02-09 12：12：11</td>
            <td style="vertical-align:middle;">妇科</td>
            <td style="vertical-align:middle;">已退号</td>
            <td style="vertical-align:middle;"><a href="look.html">详情>>></a></td>
        </tr>
  </table>
</tbody>
  
  <table class="table table-bordered table-hover definewidth m10" >
  	<tr><th colspan="5">

        <div class="inline pull-right page">
            <a id="firstPage">第一页</a>
            <a id="prePage">上一页</a>
            <span id="pageList">
                    </span>
            <a id="nextPage">下一页</a>
            <a id="lastPage">最后一页</a>
            &nbsp;&nbsp;&nbsp;共<span id="total">32</span>条记录<span class='current'> <span
                id="current_page">1</span>/<span id="total_page">33 </span></span>页
        </div>
		 <div>
             <button type="button" class="btn btn-success" id="newNav">门诊挂号</button>&nbsp;&nbsp;&nbsp;
		    <button type="button" class="btn btn-success" id="quitList" onClick="delSelected();">退号</button>&nbsp;&nbsp;&nbsp;
		    <button type="button" class="btn btn-success" id="delPro">导出Excel</button>
		
		 
		 </div>
		 
		 </th></tr>
  </table>
  
</body>
<script>
    $(function () {
        loadData();
        $("#query").click(function () {
            loadData();
        });
        $("#clear").click(function () {
            $("#registerId").val('');
            $("#doctorName").val('');
            $("#departmentName").val('');
            $("#preDate").val('');
            $("#lastDate").val('');
            loadData();
        });
    });
    function loadData() {
        let url = document.location.toString();
        let index = url.GetValue("index");
        if (index == null) {
            index = 1;
        }
        let id = url.GetValue("id");
        let name = url.GetValue("name");
        if (id != null)
            $("input[name='id']").val(id);
        if (name != null)
            $("input[name='name']").val(name);

        $("input[name='index']").val(index);

        $.ajax({
            type:"GET",
            url:"/register/list",
            data:$("#queryForm").serialize(),
            dataType:"json",
            success: function (vo) {
                let list = vo.pageInfo.list;
                let str = '';
                $("#tbody").html(str);
                for (let i = 0; i <list.length ; i++) {
                    let obj = list[i];
                    let state = '';
                    if (obj.state == 0){
                        state = '挂号';
                    }else if (obj.state == 1){
                        state = '已住院';
                    }else if (obj.state == 2){
                        state = '已出院';
                    }else if (obj.state == 3){
                        state = '已退号';
                    }
                    let hiddenState = obj.state ==3?'hidden':'';
                    str += '<tr >\n' +
                        '         \t<td style="vertical-align:middle;">' +
                        '            <input type="checkbox" name="check" value="'+obj.id+'"></td>\n' +
                        '            <td style="vertical-align:middle;">'+obj.id+'</td>\n' +
                        '            <td style="vertical-align:middle;">'+obj.doctor.name+'</td>\n' +
                        '            <td style="vertical-align:middle;">'+obj.regDate+'</td>\n' +
                        '            <td style="vertical-align:middle;">'+obj.doctor.department.name+'</td>\n' +
                        '            <td style="vertical-align:middle;">'+state+'</td>\n' +
                        '            <td style="vertical-align:middle;"><a href="look.html?index='+index+'&id='+obj.id+'">详情>>></a>&nbsp;&nbsp;&nbsp;\n' +
                        '                <a href="edit.html?index='+index+'&id='+obj.id+'">更改</a>&nbsp;&nbsp;&nbsp;\n' +
                        '                <a id="stateId" onclick="quitState('+obj.id+')" '+hiddenState+'>退号</a></td>\n' +
                        '        </tr>';
                    $("#tbody").html(str);
                }
                fillPageData(vo.pageInfo);
            }
        });
    }
    function delSelected() {
        let url = document.location.toString();
        let index = url.GetValue("index");
        var check = [];
        $("input[name = 'check']:checked").each(function () {
            check.push($(this).val())
        });
        if (check.length == 0 || check == null) {
            alert("请选择要操作的项");
            return;
        }
        if (confirm("确认退号？")){
            $.ajax({
                type: "POST",
                url: "/register/list",
                traditional: true,
                data: $("input[name = 'check']:checked").serialize() + "&_method=DELETE",
                dataType: "json",
                success: function (vo) {
                    alert(vo.msg);
                    window.location.href="index.html";
                }
            });
        }
    }
    function quitState(id) {
        let url = document.location.toString();
        let index = url.GetValue("index");
        if (index==null){
            index=1;
        }
       if (confirm("确认退号吗？")){
            $.ajax({
                type:"POST",
                url:"/register/"+id,
                data:"_method=PUT",
                dataType:"json",
                success: function(vo){
                    alert(vo.msg);
                    window.location.href="index.html?index="+index;
                }
            });
       }
    }

    function fillPageData(pageInfo) {
        let id = $("input[name='id']").val();
        let name = $("input[name='name']").val();
        let data = "&id=" + id + "&name=" + name;

        $("#total").html(pageInfo.total);
        $("#total_page").html(pageInfo.pages);
        $("#current_page").html(pageInfo.pageNum);
        $("input[name='index']").val(pageInfo.pageNum);

        $("#firstPage").attr('href', 'index.html?index=' + 1 + data);
        $("#prePage").attr('href', 'index.html?index=' + (pageInfo.pageNum - 1) + data);
        $("#nextPage").attr('href', 'index.html?index=' + (pageInfo.pageNum + 1) + data);
        $("#lastPage").attr('href', 'index.html?index=' + (pageInfo.pages) + data);
        $("#firstPage").removeAttr("disabled")
        $("#prePage").removeAttr("disabled")
        $("#nextPage").removeAttr("disabled")
        $("#lastPage").removeAttr("disabled")

        if (pageInfo.isFirstPage) {
            $("#firstPage").attr("disabled", true);
            $("#prePage").attr("disabled", true);
        }

        if (pageInfo.isLastPage) {
            $("#nextPage").attr("disabled", true);
            $("#lastPage").attr("disabled", true);
        }
        let str = "";
        let low = pageInfo.pageNum - 2;
        let high = pageInfo.pageNum + 2;
        if (low >= 1 && high <= pageInfo.pages) {
            for (let i = low; i <= high; i++) {
                str += "<a href='index.html?index=" + i + data + "' " + (i == pageInfo.pageNum ? "disabled=true" : "") + ">" + i + "</a>";
            }
        } else if (low < 1) {
            if (pageInfo.pages == 0)
                str += "<a href='index.html?index=1" + data + "' disabled=true>1</a>";
            else {
                for (let i = 1; i <= (pageInfo.pages < 5 ? pageInfo.pages : 5); i++) {
                    str += "<a href='index.html?index=" + i + data + "' " + (i == pageInfo.pageNum ? "disabled=true" : "") + ">" + i + "</a>";
                }
            }
        } else if (high > pageInfo.pages) {
            for (let i = (pageInfo.pages - 5 >= 1 ? pageInfo.pages - 4 : 1); i <= pageInfo.pages; i++) {
                str += "<a href='index.html?index=" + i + data + "' " + (i == pageInfo.pageNum ? "disabled=true" : "") + ">" + i + "</a>";
            }
        }
        $("#pageList").html(str)
    }
</script>
</html>
